#ifndef __SEMAPHORE_H
#define __SEMAPHORE_H
#include "matrix.h"
#include "dlist.h"

/**
 * the semaphore struct definition
 */
typedef struct
{
    volatile mx_usize_t vc; // the valid count
    mx_usize_t ivc;         // the initialize valid count
    mx_dlist_pt suspend;    // the thread list that wait for semaphore to be sign
} mx_semaphore_t, *mx_semaphore_pt;

/* initialize the specified semaphore */
void mx_semaphore_init (mx_semaphore_pt psem, mx_usize_t tcount, mx_usize_t vcount);
/* waiting for a semaphore to be sign within the specified time */
mx_bool_t mx_semaphore_wait (mx_semaphore_pt psem, mx_usize_t tick);
/* waiting for a semaphore to be sign forever */
void mx_semaphore_waitforever (mx_semaphore_pt psem);
/* sign a semaphore */
void mx_semaphore_sign (mx_semaphore_pt psem);

#endif
